#include "headers/initialization.h"

s8int currentPart = 0;

void initializeFileSystem(u32int startAddr, u32int endAddr)
{
	BootBlock *boot;
	setLastError(NO_ERROR);
	initPartitionning();
#ifdef DEBUG
	printf("Adding disk:  0x%H  :  0x%H\n", startAddr, endAddr);
#endif
	addDisk(startAddr, endAddr, 0);
	if(getLastError() != NO_ERROR)
	{
		printf("Error adding disk. 0x%H  :  0x%H\n", startAddr, endAddr);
		return;
	}
	currentPart = mount(0, 0);
	if(getLastError() != NO_ERROR)
	{
		printf("Error mounting partition");
		return;
	}
	
	boot = &(getMountedPartitionInfo(currentPart)->bootBlock);
#ifdef DEBUG
	printf("Partition description: %s\nBytes per block: %d\nBlocks per AllocUnit: %d\nReserved blocks: %d\n"
			"Number of file alloc tables: %d\nNumber of root dir entries: %d\nTotal blocks: %d\n"
			"Media descriptor: %d\nBlocks per alloc table: %d\nVolume serialNumber: %d\n"
			"Label: %s\nFiles system id: %s\nRootDirStart: 0x%H\nRootDirSize: 0x%H\n",
			boot->description, boot->bytesPerBlock, boot->blocksPerAllocUnit, boot->reservedBlocks,
			boot->numberOfFats, boot->rootDirEntriesN, boot->totalBlocks, boot->mediaDescriptor,
			boot->blocksPerFat, boot->volumeSerialNumber, boot->volumeLabel, boot->fileSystemId,
			boot->rootDirStartSector, boot->rootDirSize
		);
#endif
	printf("File system found: %s\n", boot->fileSystemId);
	
}
